var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken');
const secret = require('../secret');
/* GET users listing. */
router.get('/', function(req, res, next) {
  res.render('login')
});
router.post('/', function(req, res, next) {
  console.log(req.body)
  var token = jwt.sign({...req.body,iat:Math.floor(Date.now() / 1000) + (60)}, secret);
  res.cookie('token', token, {maxAge: 60 * 1000, httpOnly: true})
  res.send({message:'ok'})
});

module.exports = router;
